﻿using ReflectionStudio.Components.UserControls;
using ReflectionStudio.Core.Events;
using System;
using System.ComponentModel;
using System.Data;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
namespace WPFExcelReport
{
    public partial class MainWindow 
    {
        #region ==IsGD===========
        public static readonly DependencyProperty IsGDProperty = DependencyProperty.Register("IsGD",
            typeof(bool), typeof(MainWindow),
            new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnIsGDChanged));
        public bool IsGD
        {
            get
            {
                return (bool)GetValue(IsGDProperty);
            }
            set
            {
                SetValue(IsGDProperty, value);
            }
        }
        private static void OnIsGDChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as MainWindow;
            if (src != null)
            {
                src.IsGD = (bool)e.NewValue;
            }
        }
        #endregion
        ViewModelBase vm;
        public MainWindow()
        {
            vm = new ViewModelBase();
            DataContext = vm;
            InitializeComponent();
            ReSetTab();
            this.Name = "生产单管理";

        }
        ViewBase ui;
        public override void OnWorkflowIDChange(MessageEventArgs e)
        {
            base.OnWorkflowIDChange(e);
            string wid = e.Info.Details;
            MainTab.Children.Clear();
            string order = "";
            switch (wid)
            {
                case "AB50SPLIT": 
                    ui = new TAB50SPLIT();
                    MainTab.Children.Add(ui);
                    order = e.Info.ORDER;
                    ui.KRS = order.Substring(0, 2);
                    ui.LFD = order.Substring(2, 6);
                    ui.POS = order.Substring(8, 3);
                    cAB.KRS = order.Substring(0, 2);
                    cAB.LFD = order.Substring(2, 6);
                    cAB.POS = order.Substring(8, 3);

                    break;
                case "AB50COMBINE": 
                    ui = new TAB50COMBINE();
                    MainTab.Children.Add(ui); 
                    order = e.Info.ORDER;
                    order = order.PadRight(11);
                    ui.KRS = order.Substring(0, 2);
                    ui.LFD = order.Substring(2, 6); 
                    cAB.KRS = order.Substring(0, 2);
                    cAB.LFD = order.Substring(2, 6);  
                    break;
                case "AB50RVREP":  
                    ui = new TAB50RVREP();
                    MainTab.Children.Add(ui);
                    order = e.Info.ORDER;
                    ui.KRS = order.Substring(0, 2);
                    ui.LFD = order.Substring(2, 6);
                    ui.POS = order.Substring(8, 3);
                    cAB.KRS = order.Substring(0, 2);
                    cAB.LFD = order.Substring(2, 6);
                    cAB.POS = order.Substring(8, 3);
                    break;

            }
        }

        private void ReSetTab()
        {

        }
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            try
            {
                if (DesignerProperties.GetIsInDesignMode(this))
                    return;
                if (IsLoaded)
                    return;
                IsLoaded = true;
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            } 
        }

        private void AllocationModeCommand(object sender, RoutedEventArgs e)
        {
            if (!IsGD)
            {
                cAB.SetValue(Grid.RowProperty, 1);
                cAB.SetValue(Grid.RowSpanProperty, 2);
                IsGD = true;
            }
            else
            {
                IsGD = false;
                cAB.SetValue(Grid.RowProperty, 2);
                cAB.SetValue(Grid.RowSpanProperty, 1);
            }
        }

    }
}
